package com.cskaoyan.day24.Feild;


import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class API {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Class<?> aClass = Class.forName("com.cskaoyan.day24.Constructor.Person");
        Field[] fields = aClass.getFields();
        for (Field field : fields) {
            System.out.println(field);
        }

        System.out.println("-------------------------------------");
        Field[] declaredFields = aClass.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            System.out.println(declaredField);
        }


        System.out.println("--------------------------------------------");

        Field gender = aClass.getField("name");
        System.out.println(gender);

        System.out.println("---------------------------");
        Constructor<?> declaredConstructor = aClass.getDeclaredConstructor();
        declaredConstructor.setAccessible(true);
        Object o = declaredConstructor.newInstance();
        gender.set(o,"徐文祥");
        System.out.println(o);

        Object o1 = gender.get(o);
        System.out.println(o1);
    }
}
